<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/axios.min.js"></script>
    <script src="js/query.js"></script>

    <script>
        var user;
        /**
         * 获取当前操作用户
         */
        window.onload = function () {
            getUser();
        }

        /**
         * 修改当前用户对象的密码
         */
        function update() {
            axios.get("user/updatePwd", {
                params: {
                    id: user.id,
                    passWord: $n("new").value
                }
            }).then(resp => {
                var info = resp.data;
                if (info == "ok") {
                    alert("修改成功，即将返回登录页面");
                    /**
                     * 重新打开登录页面
                     */
                    top.window.open("login.html");
                    /**
                     * 关闭当前页面
                     */
                    window.top.close();
                }
            })
        }

        /**
         * 获取当前登录的用户
         */
        function getUser() {
            axios.get("/user/getUser").then(resp => {
                this.user = resp.data;
                console.log(this.user);
            })
        }

        /**
         * 对当前登录用户的密码以及两次输入的密码进行判断
         * 如果正确则进入用户密码的修改方法
         * 如果错误则提示
         */
        function verif() {
            var old = $n("old").value;
            var new_1 = $n("new").value;
            var new_2 = $n("new_2").value;
            if (old != this.user.pwd) {
                alert("登录密码错误");
            }
            if (new_1 != new_2) {
                alert("两次密码不一致");
            }
            if (old == this.user.pwd && new_1 == new_2) {
                update();
            }
        }

    </script>

    <link rel="stylesheet" href="css/style.css" type="text/css" media="all"/>
    <!-- Style-CSS -->
    <link rel="stylesheet" href="css/fontawesome-all.css">
</head>
<body>
<div id="bg">
    <canvas></canvas>
    <canvas></canvas>
    <canvas></canvas>
</div>

<div style="margin-left: 200px;margin-top: 100px;background-color: white;width: 500px;height: 300px;text-align: center;padding-top: 100px">
    请输入旧密码：<input type="text" id="old"><br>
    请输入新密码：<input type="text" id="new"><br>
    请确认新密码：<input type="text" id="new_2"><br>
    <input type="button" value="修改" onclick="verif()">
</div>

<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/canva_moving_effect.js"></script>
</body>
</html>